package com.http;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;

import com.android.ocean.util.common.StringUtil;
import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;

/**
 * 
 * @ClassName:FriendApplyHandleTask
 * @Description:TODO处理
 * @author zhuw
 * @date 2013-11-19 下午10:06:19
 */
public class FriendApplyHandleTask extends AsyncTask<String, Void, ResultString> {
	public static interface CallBack extends NetWorkCallBack {
		/**
		 * 
		 * @Description:TODO处理底层获取后的数据
		 * @param result
		 * @return void
		 * @author zhuw
		 * @date 2013-4-24 上午10:19:30
		 */
		public abstract void procData(String str);

	}

	CallBack callback;

	public FriendApplyHandleTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultString doInBackground(String... params) {
		ResultString data = null;
		try {
			ArrayList<NameValuePair> paramPairs=new ArrayList<NameValuePair>();
			paramPairs.add(new BasicNameValuePair("action", params[1]));
			ResEntity re=NetConUtil.postByForm(ServerPath.FRIENDS_APPLY_HANDLE_PATH+params[0],paramPairs);
			if(re.code==ResEntity.S_OK){
			    data= new ResultString(CommonData.H_FLAG_SUCCESS, null, StringUtil.unicodeToString(re.jsonStr));
			}else if(re.code==ResEntity.S_INFO){
				
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+"    "+StringUtil.unicodeToString(re.jsonStr), null);
				
			}else{
				  data= new ResultString(CommonData.H_FLAG_ERROR, "code:"+re.code+StringUtil.unicodeToString(re.jsonStr), null);
			}
		} catch (Exception e) {
			data= new ResultString(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultString result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procData(result.result);

		} else {
			callback.procError(result.msg);
		}

	}
}
